package com.base.cn.platform.os.controller.op.advert;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.service.manage.op.advert.OpAdvertPlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 广告内容
 * @author ll
 * @date 2018/5/17 11:56
 */
@Controller
@RequestMapping("/admin/op/advert")
public class AdminOpAdvertPlaceController extends AdminBaseController {

    @Autowired
    private OpAdvertPlaceService opAdvertPlaceService;


    /**
     * 去广告位置列表页面
     * @return
     */
    @RequestMapping("/toQueryOpAdvertPlaceList")
    public String toQueryOpAdvertPlaceList(){
        return resultPage("/op/advert/list_advert_place");
    }



    /**
     * 去广告位置列表页面
     * @return
     */
    @RequestMapping("/queryOpAdvertPlaceList")
    public String queryOpAdvertPlaceList(Model model){
        List<Map<String,Object>> placeList = opAdvertPlaceService.queryAdvertPlaceList();
        model.addAttribute("placeList",placeList);
        return resultPage("/op/advert/ajax_advert_place_list");
    }


    /**
     * 初始化编辑广告位置页面
     * @param id 数据ID
     * @return
     */
    @RequestMapping("/initAdvertPlaceEdit")
    public String initAdvertPlaceEdit(Model model,
                                      @RequestParam(value = "id",required = false,defaultValue = "0") BigDecimal id){

        if(DataUtil.idIsNotNull(id)){
            Map<String, Object> advertPlace = opAdvertPlaceService.queryAdvertPlaceById(id);
            model.addAttribute("advertPlace",advertPlace);
        }
        return resultPage("/op/advert/save_advert_place");
    }


    /**
     * 添加推荐位置
     * @param pamars
     * @return
     */
    @RequestMapping("/saveUpdateOpAdvertPlace")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "修改广告位数据")
    public Map<String,Object>  saveUpdateOpAdvertPlace(@RequestBody Map<String,Object> pamars){
        return opAdvertPlaceService.saveUpdateOpAdvertPlace(pamars);
    }

}
